package com.xiaoxu.intranetweb.mybatisplusSzappdb.controller.ashGate;

import com.alibaba.fastjson.JSONObject;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.business.ashGate.ManualmaterialLevelBu;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.dao.UserInfoDao;
import com.xiaoxu.intranetweb.util.SzResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 登手动料位控制器
 * @author xiaoxu
 * @date 2023/1/13 15:00
 * @version 1.0
 * @since 1.0
 */
@RestController
@RequestMapping(value="/ashGate")
public class ManualMaterialLevelController {
    @Autowired
    private ManualmaterialLevelBu manualmateriallevelBu;
    /**
     *  获取手动料位
        * @param jsonParam：AshGateId：库的id，Manual：手动模式，ManLevel：手动料位高度
     * @param request
     * @return com.xiaoxu.intranetweb.util.SzResult
     */
    @PostMapping("/setAshGate")
    public SzResult getManualmateriallevel(@RequestBody JSONObject jsonParam, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
//        库的id
        String AshGateId = jsonParam.getString("AshGateId");
//        手动模式，直接会传一个1过来
        String manual = jsonParam.getString("Manual");
//        手动料位高度
        String ManLevel = jsonParam.getString("ManLevel");
        UserInfoDao userInfoDao = new UserInfoDao();
//        拿到用户名
        String truename = userInfoDao.getUserInfoByToken(token).getSysUser().getTrueName();
//        拿到厂的id
        String plantId = request.getHeader("Plant-Id");
        return manualmateriallevelBu.setAshGate(AshGateId,manual,ManLevel,plantId,truename);
    }
    /**
     *  修改是否手动料位
     * @param jsonParam：AshGateId：库的id，Manual：手动模式
     * @param request
     * @return com.xiaoxu.intranetweb.util.SzResult
     */
    @PostMapping("/updateAshGateStatus")
    public SzResult updateAshGateStatus(@RequestBody JSONObject jsonParam, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
//        库的id
        String id = jsonParam.getString("AshGateId");
//        手动模式，直接会传一个1过来
        String manual = jsonParam.getString("Manual");
        UserInfoDao userInfoDao = new UserInfoDao();
//        拿到用户名
        String truename = userInfoDao.getUserInfoByToken(token).getSysUser().getTrueName();
//        拿到厂的id
        String plantId = request.getHeader("Plant-Id");
        return manualmateriallevelBu.updateAshGateStatus(id,manual,truename, plantId);
    }
}
